﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using TakeoutExpress.Support.Linq;
using DeliveryBoy.Workflow.Interfaces;


namespace DeliveryBoy.Workflow
{
	public partial class TakeoutProviderWorkflow : SequentialWorkflowActivity
	{

        
        public int _takeoutProviderID;
        public DateTime _broadcastStartTime;
        public DateTime _broadcastEndTime;
        public int _maxOrders;
        public int _takeoutUserCount = 0;

        private TakeoutProviderWorkflowAddSubscriberEventArgs _AddTakeoutUserEventArgs;
        public static DependencyProperty LastTakeoutUserIdProperty = DependencyProperty.Register("LastTakeoutUserId", typeof(System.Int32), typeof(DeliveryBoy.Workflow.TakeoutProviderWorkflow));

        public TakeoutProviderWorkflowAddSubscriberEventArgs AddTakeoutUserEventArgs
        {
            get { return _AddTakeoutUserEventArgs; }
            set { _AddTakeoutUserEventArgs = value; }

        }

        public int TakeoutProviderID
        {
            get
            {
                return _takeoutProviderID;
            }
            set
            {
                _takeoutProviderID = value;
            }
        }
        public DateTime BroadcastStartTime
        {
            get { return _broadcastStartTime; }
            set { _broadcastStartTime = value; }
        }
        public DateTime BroadcastEndTime
        {
            get { return _broadcastEndTime; }
            set { _broadcastEndTime = value; }
        }
        public int MaxOrders
        {
            get { return _maxOrders; }
            set { _maxOrders = value; }
        }
        private void WaitForBroadcastTimer_InitializeTimeoutDuration(object sender, EventArgs e)
        { 
            WaitForBroadcastTimer.TimeoutDuration = DateTime.Now - _broadcastStartTime;
                
        }

        private void WaitForExpiration_InitializeTimeoutDuration(object sender, EventArgs e)
        {
            WaitForBroadcastTimer.TimeoutDuration = _broadcastEndTime - DateTime.Now;
        }


        private void NotifyUsers_ExecuteCode(object sender, EventArgs e)
        {

        }

        private void handleTakeoutProviderSubscribe_Invoked(object sender, ExternalDataEventArgs e)
        {
            // cast to the proper type
            DeliveryBoy.Workflow.Interfaces.TakeoutProviderWorkflowAddSubscriberEventArgs eventArgs = (DeliveryBoy.Workflow.Interfaces.TakeoutProviderWorkflowAddSubscriberEventArgs)e;
            
            // shouldn't need to validate the addition becausee the workflow should only be running an instance at a time.  
            // do we have situations of a race condition?  

            // this is where we should submit the takeout controller.  
        }

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {

        }

        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {

        }

        private void codeActivity3_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("Internal Timer fired");
        }

        private void IncrementTakeoutUsers_ExecuteCode(object sender, EventArgs e)
        {
            _takeoutUserCount++;
        }

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Parameters")]
        public int LastTakeoutUserId
        {
            get
            {
                return ((int)(base.GetValue(DeliveryBoy.Workflow.TakeoutProviderWorkflow.LastTakeoutUserIdProperty)));
            }
            set
            {
                base.SetValue(DeliveryBoy.Workflow.TakeoutProviderWorkflow.LastTakeoutUserIdProperty, value);
            }
        }
    }
}
